package com.hospital.demo.controller.libokun;

import com.hospital.demo.model.libokun.DrugReturn;
import com.hospital.demo.service.libokun.DrugReturnService;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "药品退货单管理接口")
@CrossOrigin
@RestController
@RequestMapping("/DrugReturnController")
public class DrugReturnController {
    @Autowired
    DrugReturnService drugReturnService;


    @ApiOperation("查询全部进货单")
    @GetMapping("/SelectAllReturn")
    public ResultVO SelectAllReturn(Integer page, Integer limit) {

        List<DrugReturn> lists = drugReturnService.SelectAllReturn();

        return ResultUtils.success(lists);
    }

    @ApiOperation("按ID查找进货单")
    @GetMapping("/SelectByRId")
    public ResultVO SelectByRId(Integer drrid) {

        List<DrugReturn> lists = drugReturnService.SelectByRId(drrid);

        return ResultUtils.success(lists);
    }

    @ApiOperation("删除药品")
    @PostMapping("/DelectReturn")
    public Map<String, Object> DelectReturn(Integer drrid) {
        Map<String, Object> map = new HashMap<>();
        Integer Flag = drugReturnService.DelectReturn(drrid);
        if (Flag == 1) {
            map.put("msg", "删除操作成功");
        } else {
            map.put("msg", "删除操作失败");
        }
        return map;
    }
    @ApiOperation("添加药品")
    @PostMapping("/InsertReturn")
    public Map<String,Object> InsertReturn( DrugReturn drugreturn){
        Map<String,Object> map = new HashMap<>();
        List<DrugReturn> Flag=drugReturnService.InsertReturn(drugreturn);
        if(Flag.equals("0")){
            map.put("msg","操作成功");
        }else{
            map.put("msg","操作失败");
        }
        return map ;
    }
}
